2020-2021 Sunseeker Telemetry and Lighting System
flashctl_ex2_eraseCopyWrite.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*****************************************************************************
55 //*****************************************************************************
56 #include "driverlib.h"
57 //*****************************************************************************
58 //
59 //INFO address in flash from which data is copied
60 //
61 //*****************************************************************************
62 #define INFOC_START (0x1880)
63 //*****************************************************************************
64 //
65 //INFO address in flash to which data is copied into
66 //
67 //*****************************************************************************
68 #define INFOD_START (0x1800)
69 
70 //*****************************************************************************
71 //
72 //Number of bytes being copied
73 //
74 //*****************************************************************************
75 #define NUMBER_OF_BYTES 128
76 
77 //*****************************************************************************
78 //
79 //Dummy array of 'calibration data' - to be stored in flash
80 //
81 //*****************************************************************************
83 
84 //*****************************************************************************
85 //
86 //Delay cycles
87 //
88 //*****************************************************************************
89 #define DELAY_TIME 1000000
90 
91 //*****************************************************************************
92 //
93 //Function prototypes
94 //
95 //*****************************************************************************
96 void write_SegC (void);
97 void copy_C2D (void);
98 
99 void main (void)
100 {
101  volatile uint16_t i;
102  uint8_t value = 0;
103 
104  //Stop WDT
105  WDT_A_hold(WDT_A_BASE);
106 
107  //Set P1.0 to output direction
108  GPIO_setAsOutputPin(
109  GPIO_PORT_P1,
110  GPIO_PIN0
111  );
112 
113  //fill value for calibration data
114  for (i = 0; i < NUMBER_OF_BYTES; i++)
115  {
116  calibration_data[i] = value++;
117  }
118 
119  //Write segment C, increment value
120  write_SegC();
121 
122  //Copy segment C to D
123  copy_C2D();
124 
125  //continuous loop
126  while (1)
127  {
128  //Toggle P1.0
129  GPIO_toggleOutputOnPin(
130  GPIO_PORT_P1,
131  GPIO_PIN0
132  );
133 
134  //Delay
136  }
137 }
138 
139 //------------------------------------------------------------------------------
140 //Input = value, holds value to write to Seg C
141 //------------------------------------------------------------------------------
142 void write_SegC ()
143 {
144  uint16_t status;
145 
146  //Erase INFOC
147  do
148  {
149  FlashCtl_eraseSegment((uint8_t *)INFOC_START);
150  status = FlashCtl_performEraseCheck((uint8_t *)INFOC_START,
152  );
153  } while (status == STATUS_FAIL);
154 
155  //Flash Write
156  FlashCtl_write8(calibration_data,
157  (uint8_t *)INFOC_START,
159  );
160 }
161 
162 //------------------------------------------------------------------------------
163 //Copy Seg C to Seg D
164 //------------------------------------------------------------------------------
165 void copy_C2D (void)
166 {
167  char *FLASH_ptrC;
168  char *FLASH_ptrD;
169 
170  uint16_t status;
171 
172  //Erase INFOD
173  do {
174  FlashCtl_eraseSegment((uint8_t *)INFOD_START);
175  status = FlashCtl_performEraseCheck((uint8_t *)INFOD_START,
177  );
178  } while (status == STATUS_FAIL);
179 
180  //Initialize Flash segment C ptr
181  FLASH_ptrC = (char *)INFOC_START;
182 
183  //Initialize Flash segment D ptr
184  FLASH_ptrD = (char *)INFOD_START;
185 
186  //Flash Write
187  FlashCtl_write8((uint8_t *)FLASH_ptrC,
188  (uint8_t *)FLASH_ptrD,
190  );
191 }
192 
#define INFOD_START
#define NUMBER_OF_BYTES
#define INFOC_START
void main(void)
#define DELAY_TIME
uint8_t calibration_data[NUMBER_OF_BYTES]
void copy_C2D(void)
void write_SegC(void)
#define STATUS_FAIL
Definition: hw_memmap.h:23
__delay_cycles(500000)
uint16_t status